home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH12 / COMMON / MAPPER.H < prev    next >
C/C++ Source or Header  |  1994-09-24  |  2KB  |  68 lines

  1. #ifndef mapper_h
  2. #define mapper_h
  3. /*
  4.  * Covert a TrueColor image into "splitted colors" (regular) palette
  5.  * based on variant of Floid-Stainberg algorithm
  6.  * Some details and most of ideas were borrowed
  7.  * from the  Independent JPEG Group's software.
  8.  *              ( see the accompanying README file).
  9.  * E.Podvoysky from ^Z for WROX press book
  10.  */
  11.  
  12. class color_mapper {
  13. protected:
  14.     // are allocated  used only for dithering
  15.     BOOL on_odd_row;
  16.     int *error[3],*next_line_error[3]; // R,G and B, size = width+2
  17. public:
  18.     BOOL initialized;
  19.     BGRpalette my_colormap; /* output colormap  */
  20.     int actual_number_of_colors,width;
  21.  
  22.     color_mapper() {};
  23.     color_mapper(int colors_,int width_,BGRpalette colormap);
  24.     virtual ~color_mapper();
  25.  
  26.     int prepare_dithering(); // - 1 if not enough memory
  27.     virtual void process_line(BYTE *R, BYTE *G, BYTE *B, BYTE *out_line) {};
  28. };
  29.  
  30.  
  31. class color_mapper_splitted: public color_mapper {
  32. protected:
  33.     BYTE *convert_table[3], // convert input value to (partial) color index
  34.                 // input range from 0 to 2*max_color_value
  35.          *value_table[3],    // values of color componente by index
  36.          color_num[3],
  37.          *convert_table0[3];      //actual pointers on allocated arrays!
  38.  
  39.     int max_color_value;
  40.  
  41.     void init(int width_, BYTE *color_values[3], BYTE color_num_[3]); //sub proc. for constructors
  42.  
  43.     // for gray and splitted colors :
  44.     // preapare table to convert input value to (partial) color #
  45.     virtual void prepare_table(BYTE *values,int color_index);
  46.  
  47.     int select_colors_num(int max_colors);
  48.             // returns (-1) if max_colors is bad
  49.     virtual void process_one_color(BYTE *in, BYTE *out_line, int col_ind);
  50.  
  51. public:
  52.     color_mapper_splitted() {};
  53.     color_mapper_splitted(int width_, BYTE *color_values[3], BYTE color_num_[3]);
  54.  
  55.     color_mapper_splitted(int colors_,int width_,int max_color_value_); //short cut
  56.     virtual ~color_mapper_splitted();
  57.  
  58.     virtual void process_line(BYTE *R, BYTE *G, BYTE *B, BYTE *out_line);
  59. };
  60.  
  61. class color_mapper_gray: public color_mapper_splitted {
  62. public:
  63.     color_mapper_gray(int colors_,int width_,int max_color_value_);
  64.     color_mapper_gray() {}; // formal
  65.     virtual void one_row(BYTE *source, BYTE *out_line);
  66. };
  67. #endif
  68.